import { createRouter, createWebHashHistory } from "vue-router";

export const routes = [
  // 这里可以添加路由配置
  {
    path: "/",
    redirect: "/home",

    component: () => import("@/layout/index.vue"),
    children: [
      {
        path: "home",
        component: () => import("@/views/home/index.vue"),
        children: [
          {
            path: "index",
            component: () => import("@/views/index/index.vue"),
            meta: {
              title: "首页",
              showInMenu:true,
              icon: "HomeFilled",
            },
          },
          {
            path: "myResume",
            component: () => import("@/views/myResume/index.vue"),
            meta: {
              title: "我的简历",
              showInMenu:true,
              icon: "Document",
            },
          },
          {
            path: "myInfo",
            component: () => import("@/views/myInfo/index.vue"),
            meta: {
              title: "我的信息",
              showInMenu:true,
              icon:'User'
            },
          },
          {
            path: "modelGroup",
            component: () => import("@/views/modelGroup/index.vue"),
            meta: {
              title: "简历模板",
              showInMenu:true,
              icon:'FolderRemove'
            },
          },
          {
            path: "setting",
            component: () => import("@/views/setting/index.vue"),
            meta: {
              title: "设置",
              showInMenu:true,
              icon:'Setting'
            },
          },
          {
            path: "apiKeys",
            component: () => import("@/views/apiKeys/index.vue"),
            meta: {
              title: "API设置",
              showInMenu:true,
              icon:'Key'
            },
          },
        ],
      },
    ],
  },
  {
    path: "/resumeMaker",
    redirect: "/resumeMaker/classical",
    meta: {
      title: "简历制作",
    },
    component: () => import("@/views/resumeMaker/index.vue"),
    children: [
      {
        path: "classical",
        component: () => import("@/views/resumeMaker/models/classical.vue"),
        meta: {
          title: "经典简历",
        },
      },
      {
        path: "moden",
        component: () => import("@/views/resumeMaker/models/moden.vue"),
        meta: {
          title: "现代简历",
        },
      },
      
    ],
  },

  //login
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: {
      title: "登录",
    },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
router.beforeEach((to, from, next) => {
  // 从路由元信息中获取标题
  if (to.meta.title) {
    document.title ='简历制作'+( to.meta.title? ' - '+to.meta.title : '')
  }
  console.log(!!localStorage.getItem('token'))
  //排除login 页面
  console.log(to.path)
  if(to.path!=='/login'&&(localStorage.getItem('token')=== null|| localStorage.getItem('token')=== '')){
    //重定向
    console.log(localStorage.getItem('token'))
    window.location.href = 'http://111.229.25.148:8088/login?redirect=http://111.229.25.148:5173/#/login'
  }
  next()
})
export default router;
